<html>
<head>
	<meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- HTML5 shim for IE8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <![endif]-->

	<link href="/statics/simpleboot/themes/bluesky/theme.min.css" rel="stylesheet">
    <link href="/statics/simpleboot/css/simplebootadmin.css" rel="stylesheet">
    <link href="/statics/js/artDialog/skins/default.css" rel="stylesheet" />
    <link href="/statics/simpleboot/font-awesome/4.2.0/css/font-awesome.min.css"  rel="stylesheet" type="text/css">
    <style>
		.length_3{width: 180px;}
	</style>
	<!--[if IE 7]>
	<link rel="stylesheet" href="/statics/simpleboot/font-awesome/4.2.0/css/font-awesome-ie7.min.css">
	<![endif]-->
<script type="text/javascript">
//全局变量
var GV = {
    DIMAUB: "/",
    JS_ROOT: "statics/js/",
    TOKEN: ""
};
</script>
<body class="J_scroll_fixed">
<style>
#content td{ line-height:24px;  text-align:center;  vertical-align:middle;}
.hidden{ display:none;}
</style>
<div class="wrap jj">

  <div class="common-form">
    <div class="table_list">
        <div class="row">
            <div class="span10">
            	<table id="content" class="table table-bordered table-hover"><tr><td>正在加载...</td></tr></table>
            	<button type="button" class="btn btn-primary" id="att_add">增加属性</button>
            </div>
            <div class="span2">
				<div>
				<!-- <input type="text" id="newid" value="" placeholder="被拷贝的产品ID" style="width:90%"/><br/> -->
				<!-- <button type="button" id="submit2" class="btn btn-primary">拷贝</button> -->
			  </div>
            	<div id="json"></div>
            </div>
        </div>
    </div>
  <div class="form-actions">
        <button type="button" id="submit" class="btn btn-primary">提交</button>
        <a class="btn" href="{:U('Product/index')}">返回</a>
  </div>


</div>
<script type="text/javascript" src="__PUBLIC__/admin/lib/jquery/1.9.1/jquery.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.js"></script>
<script type="text/javascript" src="__ROOT__/statics/js/wind.js"></script>
<script type="text/javascript" src="__ROOT__/statics/js/common.js"></script>
<script type="text/javascript" src="__ROOT__/statics/js/product_att.js"></script>
<script type="text/javascript" src="__ROOT__/statics/js/content_addtop.js"></script>
<script>
	$("#att_add").on("click",function(){
		new_att('content');	
	});
	$("#submit").on("click",function(){
		var contents = $('#content').find('tr');
		if(contents.length>0)
		{
			var temp = [];
			contents.each(function(index){
				var x = JSON.parse($('.hidden').eq(index).html());
				temp.push(x);//属性数组集合
			});
			$.ajax({
				url : "{:U('set_attribute')}",
				type: "POST",				
				datatype:"json",
				data:{content:temp,id:{$pid}},
				success: function(msg){
					alert(msg.info);
				}
			  });

		}
	});

	$("#submit2").on("click",function(){
		var nid = $('#newid').val();
		if(nid.length>0)
		{
			$.ajax({
				url : "{:U('copy_attribute')}",
				type: "POST",				
				datatype:"json",
				data:{newid:nid,id:{$pid}},
				success: function(msg){
					alert(msg.info);
					inti();
				}
			  });

		}
	});
	function intite(){
		$.ajax({
			url:"get_attribute",
			datatype:"json",
			type: "POST",
			data:{id:{$pid}},
			success : function(data){
				var $content = $("#content");
			 	$content.empty();
				if(data.info=="no"){
					$content.html("<span>加载失败</span>");	
				}else{
					$content.html(draw(data.data));									
				}			
			}
	   });
   };
   intite();

</script>
</body>
</html>